#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int  p[1001];
char l[1001];

int ff(int y)
{
    for (int i = 0; i <= y; i++) 
    {
        if (p[i] != p[y - i])
            return 0;
    }
    return 1;
}

int main()
{
    int i, j, k;
    int n, x = 0, y = 0, z = 0;
    scanf("%d %s", &n, l);
    y = strlen(l) - 1;
    for (i = 0; i <= y; i++) 
    {
        if (l[i] >= '0' && l[i] <= '9')
            p[i] = l[i] - '0';
        if (l[i] >= 'a' && l[i] <= 'z')
            p[i] = l[i] - 'a' + 10;
        if (l[i] >= 'A' && l[i] <= 'Z')
            p[i] = l[i] - 'A' + 10;
    }
    for (i = 0; i <= 30; i++) 
    {
        if (ff(y))
        {
            printf("%d", i);
            break;
        }
        int s[1001] = { 0 };
        for (j = 0, k = y; j <= y; j++, k--) 
        {
            s[j] = p[k];
        }
        for (j = 0; j <= y; j++) 
        {
            p[j] += s[j];
            p[j + 1] += p[j] / n;
            p[j] %= n;
        }
        if (p[j] != 0)
            y = j;
    }
    if (i > 30)
        printf("Impossible");
    return 0;
}